using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
using XBLib.Dal.AdoDal;
using DataInfo;
using KenLib.Common;
namespace KenLib.Dal
{
    public class 会社履歴情報Dao : BaseAdoDao
    {
        private string m_requestTime;
        private string m_displayTime;
        public int Insert(会社履歴情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                List<DbParameter> ls = new GlobalDao().CreateArrayParam(obj, "廃止区分,会社名,部門名,仕事内容,主な実績,開始年月日,終了年月日,企業ID,経歴職歴,企業分類コード,社員ID");
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Insert_TraineeWorkedCompInfo, CommandType.StoredProcedure, ls.ToArray());
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "INSERT", "Insert_TraineeWorkedCompInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Update(会社履歴情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                List<DbParameter> ls = new GlobalDao().CreateArrayParam(obj, "ID,廃止区分,会社名,部門名,仕事内容,主な実績,開始年月日,終了年月日,企業ID,経歴職歴,企業分類コード,社員ID");

                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Update_TraineeWorkedCompInfo, CommandType.StoredProcedure, ls.ToArray());
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "UPDATE", "Update_TraineeWorkedCompInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Delete(int id)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param0 = _daoHelper.CreateParameter("@ID", id, DbType.Int32);

                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Delete_TraineeWorkedCompInfo, CommandType.StoredProcedure, param0);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "DELETE", "Delete_TraineeWorkedCompInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        /// <summary>
        /// Vh
        /// Select a part of Table 会社履歴情報
        /// </summary>
        /// <param name="社員ID"></param>
        /// <returns></returns>
        //public List<会社履歴情報> SelectPartial(String 社員ID)
        //{
        //    try
        //    {
        //        DbCommand com = _daoHelper.CreateCommand(CommandNameManager.sp_Select会社履歴情報_Partial_53, CommandType.StoredProcedure);
        //        DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
        //        com.Parameters.Add(para);
        //        return _businessObjectHelper.FillToList<会社履歴情報>(_daoHelper.Query(com));
        //    }
        //    catch (Exception v)
        //    {
        //        throw new Exception(v.Message);
        //    }

        //}
        public DataTable SelectPartial(string 社員ID)
        {
            try
            {
                DbCommand com = _daoHelper.CreateCommand(CommandNameManager.sp_Select会社履歴情報_Partial_53, CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                com.Parameters.Add(para);
                DataTable dt = _daoHelper.Query(com);
                
                return dt;
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }

        }

        public DataTable SelectPartialOrg53(string 社員ID)
        {
            try
            {
                DbCommand com = _daoHelper.CreateCommand("sp_Select会社履歴情報_Partial_Org_53_Hoat", CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                com.Parameters.Add(para);
                DataTable dt = _daoHelper.Query(com);

                return dt;
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }
        }

        public DataTable SelectPartial_12(String 社員ID)
        {
            try
            {
                DbCommand com = _daoHelper.CreateCommand(CommandNameManager.sp_Select会社履歴情報_Partial_12, CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                com.Parameters.Add(para);
                return _daoHelper.Query(com);
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }

        }


        /// <summary>
        /// Vh
        /// Insert columns of Table 会社履歴情報
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertPartial(会社履歴情報 obj)
        {
            int i = 0;
            try
            {
                DbCommand com = _daoHelper.CreateCommand(CommandNameManager.sp_Insert会社履歴情報_Partial_53, CommandType.StoredProcedure);

                DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
                DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
                DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
                DbParameter para4 = _daoHelper.CreateParameter("@仕事内容", obj.仕事内容);
                DbParameter para5 = _daoHelper.CreateParameter("@主な実績", obj.主な実績);
                DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
                DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
                DbParameter para7_1 = _daoHelper.CreateParameter("@企業分類コード", obj.企業分類コード);
                DbParameter para8 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
                com.Parameters.Add(para1);
                com.Parameters.Add(para2);
                com.Parameters.Add(para3);
                com.Parameters.Add(para4);
                com.Parameters.Add(para5);
                com.Parameters.Add(para6);
                com.Parameters.Add(para7);
                com.Parameters.Add(para7_1);
                com.Parameters.Add(para8);

                i = _daoHelper.Execute(com);
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }
            return i;
        }
        #region TUNG
        public DataTable getGrv_会社履歴(int 社員ID)
        {
            DbParameter dbParam1 = _daoHelper.CreateParameter("@社員ID", 社員ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand("sp_getGrv_会社履歴_TUNG", CommandType.StoredProcedure, dbParam1);
            return _daoHelper.Query(dbcommand);
        }
        #endregion


        public int update_ModeInsert_js56_Vh(会社履歴情報 obj)
        {
            int i = 0;
            try
            {
                DbCommand com = _daoHelper.CreateCommand("update_ModeInsert_js56_Vh", CommandType.StoredProcedure);

                //DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
                DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
                DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
                DbParameter para4 = _daoHelper.CreateParameter("@仕事内容", obj.仕事内容);
                DbParameter para5 = _daoHelper.CreateParameter("@主な実績", obj.主な実績);
                DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
                DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
                DbParameter para7_1 = _daoHelper.CreateParameter("@企業分類コード", obj.企業分類コード);
                DbParameter para8 = _daoHelper.CreateParameter("ID", obj.ID);
                //com.Parameters.Add(para1);
                com.Parameters.Add(para2);
                com.Parameters.Add(para3);
                com.Parameters.Add(para4);
                com.Parameters.Add(para5);
                com.Parameters.Add(para6);
                com.Parameters.Add(para7);
                com.Parameters.Add(para7_1);
                com.Parameters.Add(para8);

                i = _daoHelper.Execute(com);
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }
            return i;
        }

        public DataTable sp_SelectModeUpdate_js56_Hoat(String 社員ID)
        {
            try
            {
                DbCommand com = _daoHelper.CreateCommand("sp_SelectModeUpdate_js56_Hoat", CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@ID", 社員ID);
                com.Parameters.Add(para);
                return _daoHelper.Query(com);
            }
            catch (Exception v)
            {
                throw new Exception(v.Message);
            }

        }

        #region VHoat
        public int InsertPartialTable(会社履歴情報 obj, out int IdCurrent)
        {
            int i = 0;
            IdCurrent = 0;
            DbCommand com = _daoHelper.CreateCommand("sp_Insert会社履歴情報_Partial_53_Hoat_2", CommandType.StoredProcedure);

            DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
            DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
            DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
            DbParameter para4 = _daoHelper.CreateParameter("@仕事内容", obj.仕事内容);
            DbParameter para5 = _daoHelper.CreateParameter("@主な実績", obj.主な実績);
            DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
            DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
            DbParameter para7_1 = _daoHelper.CreateParameter("@企業分類コード", obj.企業分類コード);
            DbParameter para8 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter para9 = _daoHelper.CreateParameter("@ID", 0);
            para9.Direction = ParameterDirection.Output;

            com.Parameters.Add(para1);
            com.Parameters.Add(para2);
            com.Parameters.Add(para3);
            com.Parameters.Add(para4);
            com.Parameters.Add(para5);
            com.Parameters.Add(para6);
            com.Parameters.Add(para7);
            com.Parameters.Add(para7_1);
            com.Parameters.Add(para8);
            com.Parameters.Add(para9);
            
            i = _daoHelper.Execute(com);
            IdCurrent = Int32.Parse(com.Parameters["@ID"].Value.ToString());
            
            return i;
        }

        public int UpdatePartialTable(会社履歴情報 obj, int IdCurrent)
        {
            int i = 0;

            DbCommand com = _daoHelper.CreateCommand("sp_Update会社履歴情報_Partial_53_Hoat", CommandType.StoredProcedure);

            DbParameter para1 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
            DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
            DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
            DbParameter para4 = _daoHelper.CreateParameter("@仕事内容", obj.仕事内容);
            DbParameter para5 = _daoHelper.CreateParameter("@主な実績", obj.主な実績);
            DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
            DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
            DbParameter para7_1 = _daoHelper.CreateParameter("@企業分類コード", obj.企業分類コード);
            
            DbParameter para9 = _daoHelper.CreateParameter("@ID", IdCurrent);


            com.Parameters.Add(para1);
            com.Parameters.Add(para2);
            com.Parameters.Add(para3);
            com.Parameters.Add(para4);
            com.Parameters.Add(para5);
            com.Parameters.Add(para6);
            com.Parameters.Add(para7);
            com.Parameters.Add(para7_1);
            
            com.Parameters.Add(para9);

            i = _daoHelper.Execute(com);

            return i;
        }

        /// <summary>
        /// Check exists a duplicate
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool checkExistIn会社履歴情報InsertMode(会社履歴情報 obj)
        {
            bool flag = false;

            DbCommand com = _daoHelper.CreateCommand("checkExistIn会社履歴情報InsertMode_JS56_Hoat", CommandType.StoredProcedure);
            
            DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
            DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
            DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
            DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
            DbParameter para8 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);

            com.Parameters.Add(para2);
            com.Parameters.Add(para3);
            com.Parameters.Add(para6);
            com.Parameters.Add(para7);
            com.Parameters.Add(para8);

            DataTable dt = _daoHelper.Query(com);
            if (dt.Rows.Count > 0)
                flag = true;

            return flag;
        }

        /// <summary>
        /// check has changed data?
        /// </summary>
        /// <param name="obj"></param>
        /// <returns> true: if has changed</returns>
        public bool checkHasChangedIn会社履歴情報UpdateCurrent(会社履歴情報 obj)
        {
            bool flag = true;//Has changed

            DbCommand com = _daoHelper.CreateCommand("checkHasChangedIn会社履歴情報UpdateCurrent_JS56_Hoat", CommandType.StoredProcedure);

            DbParameter para2 = _daoHelper.CreateParameter("@会社名", obj.会社名);
            DbParameter para3 = _daoHelper.CreateParameter("@部門名", obj.部門名);
            DbParameter para6 = _daoHelper.CreateParameter("@開始年月日", obj.開始年月日);
            DbParameter para7 = _daoHelper.CreateParameter("@終了年月日", obj.終了年月日);
            DbParameter para8 = _daoHelper.CreateParameter("@ID", obj.ID);

            com.Parameters.Add(para2);
            com.Parameters.Add(para3);
            com.Parameters.Add(para6);
            com.Parameters.Add(para7);
            com.Parameters.Add(para8);

            DataTable dt = _daoHelper.Query(com);
            if (dt.Rows.Count > 0)
                flag = false;//No change

            return flag;
        }

        #endregion Hoat
 
    }
}
